# 输入: [0,1,2,4,5,7]
# 输出: ["0->2","4->5","7"]


class Solution:
    def summaryRanges(self, nums: list) -> list:
        if not nums:
            return []
        res, start_num, end_num = [], nums[0], nums[0]
        for index in range(1, len(nums)):
            if end_num + 1 == nums[index]:
                end_num = nums[index]
            else:
                if start_num != end_num:
                    res.append("%s->%s" % (start_num, end_num))
                    # res.append(str(start_num) + "->" + str(end_num))
                else:
                    res.append(str(start_num))
                start_num, end_num = nums[index], nums[index]
        else:
            if start_num != end_num:
                res.append("%s->%s" % (start_num, end_num))
            else:
                res.append(str(start_num))
            return res


a = Solution()
print(a.summaryRanges([0, 1, 2, 4, 5, 7]))
